home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / comp / info.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  3.4 KB  |  123 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: info.c,v 1.4 94/10/05 20:55:09 nkramer Exp $
  27. *
  28. * This file maintains info about builtin/magic functions/names.
  29. *
  30. \**********************************************************************/
  31.  
  32. #include "../compat/std-c.h"
  33.  
  34. #include "mindycomp.h"
  35. #include "src.h"
  36. #include "sym.h"
  37. #include "info.h"
  38.  
  39.  
  40. /* Binop infos. */
  41.  
  42. struct binop_info_chain {
  43.     struct symbol *symbol;
  44.     struct binop_info_chain *next;
  45.     struct binop_info info;
  46. };
  47.  
  48. static struct binop_info_chain *BinopInfos = NULL;
  49. static struct binop_info DefaultBinopInfo = {0, TRUE};
  50.  
  51. struct binop_info *lookup_binop_info(struct id *id)
  52. {
  53.     struct binop_info_chain *p;
  54.  
  55.     for (p = BinopInfos; p != NULL; p = p->next)
  56.     if (p->symbol == id->symbol)
  57.         return &p->info;
  58.     return &DefaultBinopInfo;
  59. }
  60.  
  61. static void push_binop_info(char *name, int prec, boolean left)
  62. {
  63.     struct binop_info_chain *new = malloc(sizeof(struct binop_info_chain));
  64.  
  65.     new->symbol = symbol(name);
  66.     new->info.precedence = prec;
  67.     new->info.left_assoc = left;
  68.     new->next = BinopInfos;
  69.     BinopInfos = new;
  70. }
  71.  
  72.  
  73. /* Function infos. */
  74.  
  75. struct function_info_chain {
  76.     struct symbol *symbol;
  77.     boolean internal;
  78.     struct function_info_chain *next;
  79.     struct function_info info;
  80. };
  81.  
  82. static struct function_info_chain *FunctionInfos = NULL;
  83.  
  84. struct function_info *lookup_function_info(struct id *id, boolean createp)
  85. {
  86.     struct function_info_chain *p;
  87.  
  88.     for (p = FunctionInfos; p != NULL; p = p->next)
  89.     if (p->symbol == id->symbol && p->internal == id->internal)
  90.         return &p->info;
  91.     if (createp) {
  92.     p = malloc(sizeof(struct function_info_chain));
  93.     p->symbol = id->symbol;
  94.     p->internal = id->internal;
  95.     p->next = FunctionInfos;
  96.     FunctionInfos = p;
  97.     p->info.srctran = NULL;
  98.     return &p->info;
  99.     }
  100.     return NULL;
  101. }
  102.  
  103.  
  104. /* Init stuff. */
  105.  
  106. void init_info(void)
  107. {
  108.     push_binop_info(":=", 1, FALSE);
  109.     push_binop_info("|", 2, FALSE);
  110.     push_binop_info("&", 3, FALSE);
  111.     push_binop_info("<", 4, TRUE);
  112.     push_binop_info("<=", 4, TRUE);
  113.     push_binop_info("=", 4, TRUE);
  114.     push_binop_info("==", 4, TRUE);
  115.     push_binop_info("~=", 4, TRUE);
  116.     push_binop_info(">=", 4, TRUE);
  117.     push_binop_info(">", 4, TRUE);
  118.     push_binop_info("+", 5, TRUE);
  119.     push_binop_info("-", 5, TRUE);
  120.     push_binop_info("*", 6, TRUE);
  121.     push_binop_info("/", 6, TRUE);
  122. }
  123.